package com.zh.onlineexam.common.response;

import cn.dev33.satoken.stp.StpUtil;
import lombok.Data;

/**
 * @className ResultData
 * @Description TODO
 * @Auther 29934
 * @Date 2022/9/11 10:26
 * @Version 1.0
 **/
@Data
public class ResultData<T> {
    /** 结果状态 ,具体状态码参见ResultData.java*/
    private int code;
    private String msg;
    private String token;
    private T data;
    private long timestamp ;


    public ResultData (){
        this.timestamp = System.currentTimeMillis();
    }


    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCode.RC100.getCode());
        resultData.setMsg(ReturnCode.RC100.getMessage());
        resultData.setData(data);
        resultData.setToken(StpUtil.getTokenValue());
        return resultData;
    }

    public static <T> ResultData<T> fail(int code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCode.RC300.getCode());
        resultData.setMsg(ReturnCode.RC300.getMessage());
        return resultData;
    }
}
